package main

import (
	"fmt"
	"os"
)

func main() {
	err := write("test.txt", "这是一个测试")
	if err != nil {
		return
	}
}

func write(file string, content string) error {
	openFile, err := os.OpenFile(file, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
	defer openFile.Close()
	if err != nil {
		return err
	}
	fmt.Println(openFile)
	// 写入内容
	line, err := openFile.WriteString(content)
	openFile.Write([]byte("还能这么写"))
	if err != nil {
		return err
	}
	fmt.Println(line)
	return nil
}
